package org.kwin.spring.web;

import org.kwin.spring.context.AnnotationConfigApplicationContext;
import org.kwin.spring.web.handler.HandlerMapping;
import org.kwin.spring.web.servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Properties;

/**
 * @author : wangkai
 * @version V1.0
 * @Package org.kwin.spring.web
 * @Description:
 * @date 2021年09月28日 9:26
 **/
@WebServlet(urlPatterns = "/*")
public class DispatchServlet extends HttpServlet implements BaseServlet {
    
    private Class<?> clazz;
    private Properties properties;
    
    public DispatchServlet(Class<?> clazz, Properties properties) {
        this.clazz = clazz;
        this.properties = properties;
    }
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        this.doPost(req, resp);
    }
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        HandlerMapping handlerMapping = new HandlerMapping();
        handlerMapping.request(req, resp);
    }
    
    @Override
    public void loadOnStartup() {
        System.out.println("Spring 开始加载");
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(clazz,properties);
        System.out.println(context.getIoc());
        System.out.println("------------");
        System.out.println(context.getPorxyMap());
        System.out.println("IOC容器初始化完毕");
    
    }
}
